package com.vma.shoeSystem.controller;

import com.jfinal.core.Controller;
import com.vma.shoeSystem.util.ReturnsUtil;
import com.vma.shoes.bizModel.model.PostageSettings;
import com.vma.shoes.bizModel.model.ShoesConfig;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by chenzui on 2017/5/30.
 */
public class ConfigController extends Controller {
    public void initConfig(){
        ShoesConfig config = ShoesConfig.dao.findById(1);
        Map postageMap = new HashMap();
        postageMap.put("guang",PostageSettings.dao.findById(1));
        postageMap.put("lots",PostageSettings.dao.findById(2));
        postageMap.put("others",PostageSettings.dao.findById(8));

        setAttr("config",config);
        setAttr("postageMap",postageMap);
        renderVelocity("/shop/shoeconfig.html");
    }

    public void updateConfigQQ(){
        String qq = getPara("qq");
        ShoesConfig.dao.findById(1).setQq(qq).update();
        renderJson(ReturnsUtil.returnSuccess("success"));
    }

    public void updateConfigPrice(){
        String price_one = getPara("price_one");
        String price_two = getPara("price_two");
        String price_three = getPara("price_three");

        ShoesConfig.dao.findById(1).setPriceOne(price_one).setPriceTwo(price_two).setPriceThree(price_three).update();
        renderJson(ReturnsUtil.returnSuccess("success"));
    }

    public void updateConfigPostage(){
        String location_1_status = getPara("location_1_status");
        String location_1_price = getPara("location_1_price");
        String location_1_top = getPara("location_1_top");
        String location_2_status = getPara("location_2_status");
        String location_2_price = getPara("location_2_price");
        String location_2_top = getPara("location_2_top");
        String location_3_status = getPara("location_3_status");
        String location_3_price = getPara("location_3_price");
        String location_3_top = getPara("location_3_top");

        PostageSettings.dao.findById(1).setStatus(location_1_status).setTopLine(Float.valueOf(location_1_top)).setPrice(Float.valueOf(location_1_price)).update();
        PostageSettings.dao.findById(8).setStatus(location_3_status).setTopLine(Float.valueOf(location_3_top)).setPrice(Float.valueOf(location_3_price)).update();
        PostageSettings.dao.findById(2).setStatus(location_2_status).setTopLine(Float.valueOf(location_2_top)).setPrice(Float.valueOf(location_2_price)).update();
        PostageSettings.dao.findById(3).setStatus(location_2_status).setTopLine(Float.valueOf(location_2_top)).setPrice(Float.valueOf(location_2_price)).update();
        PostageSettings.dao.findById(4).setStatus(location_2_status).setTopLine(Float.valueOf(location_2_top)).setPrice(Float.valueOf(location_2_price)).update();
        PostageSettings.dao.findById(5).setStatus(location_2_status).setTopLine(Float.valueOf(location_2_top)).setPrice(Float.valueOf(location_2_price)).update();
        PostageSettings.dao.findById(6).setStatus(location_2_status).setTopLine(Float.valueOf(location_2_top)).setPrice(Float.valueOf(location_2_price)).update();
        PostageSettings.dao.findById(7).setStatus(location_2_status).setTopLine(Float.valueOf(location_2_top)).setPrice(Float.valueOf(location_2_price)).update();
        renderJson(ReturnsUtil.returnSuccess("success"));
    }
}
